/* Replication file for "Now or Later?"*/
/* Regression analysis in "Turnout in the Morning vs. Afternoon of Election Day"*/

use morning_vs_afternoon.dta, clear

* Variables 
egen km = group(ken muni)
tab ken, gen(kk)
gen time1 = time == 11
gen time2 = time == 18
gen time1drain = time1 * drain_17_14
gen time2drain = time2 * drain_17_14
gen time1vmargin = time1 * vmargin
gen time2vmargin = time2 * vmargin
gen time1lpop = time1 * lpop
gen time2lpop = time2 * lpop
gen time1p65 = time1 * p65
gen time2p65 = time2 * p65
gen time1pcollege = time1 * pcollege
gen time2pcollege = time2 * pcollege
egen muniid = group(muni)


* Table 1
estpost summarize turnout_17_14 rain_17_14 drain_17_14
estout, style(tex) cells("mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3))") label
eststo clear

estpost summarize turnout_17_14 rain_17_14 if time == 11
estout, style(tex) cells("mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3))") label
eststo clear

estpost summarize turnout_17_14 rain_17_14 if time == 18
estout, style(tex) cells("mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3))") label
eststo clear


* Table 2
qui eststo: reg turnout_17_14 ibn.time rain_17_14, noconstant cluster(km)
qui eststo: reg turnout_17_14 ibn.time rain_17_14 kk1-kk4 kk6-kk25, noconstant cluster(km)
qui eststo: reg turnout_17_14 ibn.time ibn.time#c.drain_17_14 rain_17_14, noconstant cluster(km)
qui eststo: reg turnout_17_14 ibn.time ibn.time#c.drain_17_14 rain_17_14 kk1-kk4 kk6-kk25, noconstant cluster(km)
estout, style(tex) cells(b(star fmt(3) ) se(par fmt(3))) label  collabels(none)  stats(r2_a N) starlevels($*$ 0.10 $**$ 0.05 $***$ 0.01) drop(kk*)
eststo clear  
  
* Table 3
qui eststo: reg turnout_17_14 ibn.time ibn.time#c.drain_17_14 ibn.time#c.vmargin rain_17_14  kk1-kk4 kk6-kk25, noconstant cluster(km)
qui eststo: reg turnout_17_14 ibn.time ibn.time#c.drain_17_14 ibn.time#c.lpop rain_17_14  kk1-kk4 kk6-kk25, noconstant cluster(km)
qui eststo: reg turnout_17_14 ibn.time ibn.time#c.drain_17_14 ibn.time#c.p65 rain_17_14  kk1-kk4 kk6-kk25, noconstant cluster(km)
qui eststo: reg turnout_17_14 ibn.time ibn.time#c.drain_17_14 ibn.time#c.pcollege rain_17_14  kk1-kk4 kk6-kk25, noconstant cluster(km)
estout, style(tex) cells(b(star fmt(3) ) se(par fmt(3))) label  collabels(none)  stats(r2_a N) starlevels($*$ 0.10 $**$ 0.05 $***$ 0.01) drop(kk*)
eststo clear

* Table 4
qui eststo: reg turnout_17_14 ibn.time ibn.time#c.drain_17_14 rain_17_14 kk1-kk4 kk6-kk25 if m65 == 0, noconstant cluster(km)
qui eststo: reg turnout_17_14 ibn.time ibn.time#c.drain_17_14 rain_17_14 kk1-kk4 kk6-kk25 if m65 == 1, noconstant cluster(km)
estout, style(tex) cells(b(star fmt(3) ) se(par fmt(3))) label  collabels(none)  stats(r2_a N) starlevels($*$ 0.10 $**$ 0.05 $***$ 0.01) drop(kk*)
eststo clear
 
* Table A.2
qui eststo: ols_spatial_HAC turnout_17_14 time1 time2 time1drain time2drain rain_17_14 kk1-kk4 kk6-kk25, ///
	lat(POINT_Y) lon(POINT_X) t(time) p(muniid) dist(20) lag(1) bartlett disp
qui eststo: ols_spatial_HAC turnout_17_14 time1 time2 time1drain time2drain  time1vmargin time2vmargin rain_17_14 kk1-kk4 kk6-kk25, ///
	lat(POINT_Y) lon(POINT_X) t(time) p(muniid) dist(20) lag(1) bartlett disp
qui eststo: ols_spatial_HAC turnout_17_14 time1 time2 time1drain time2drain  time1lpop time2lpop rain_17_14 kk1-kk4 kk6-kk25, ///
	lat(POINT_Y) lon(POINT_X) t(time) p(muniid) dist(20) lag(1) bartlett disp
qui eststo: ols_spatial_HAC turnout_17_14 time1 time2 time1drain time2drain  time1p65 time2p65 rain_17_14 kk1-kk4 kk6-kk25, ///
	lat(POINT_Y) lon(POINT_X) t(time) p(muniid) dist(20) lag(1) bartlett disp
qui eststo: ols_spatial_HAC turnout_17_14 time1 time2 time1drain time2drain  time1pcollege time2pcollege rain_17_14 kk1-kk4 kk6-kk25, ///
	lat(POINT_Y) lon(POINT_X) t(time) p(muniid) dist(20) lag(1) bartlett disp
estout, style(tex) cells(b(star fmt(3) ) se(par fmt(3))) label  collabels(r2_a N) starlevels($*$ 0.10 $**$ 0.05 $***$ 0.01) drop(kk*)
eststo clear
  
* Table A.3
qui eststo: ols_spatial_HAC turnout_17_14 time1 time2 time1drain time2drain rain_17_14 kk1-kk4 kk6-kk23 kk25 if m65 == 0, ///
	lat(POINT_Y) lon(POINT_X) t(time) p(muniid) dist(20) lag(1) bartlett disp
qui eststo: ols_spatial_HAC turnout_17_14 time1 time2 time1drain time2drain rain_17_14 kk1-kk4 kk6-kk25 if m65 == 1, ///
	lat(POINT_Y) lon(POINT_X) t(time) p(muniid) dist(20) lag(1) bartlett disp
estout, style(tex) cells(b(star fmt(3) ) se(par fmt(3))) label  collabels(r2_a N) starlevels($*$ 0.10 $**$ 0.05 $***$ 0.01) drop(kk*)
eststo clear
